"""
    多进程执行文本向量化
"""

import os
import time
import multiprocessing
from multiprocessing import Pool 


# 生成提问时的prompt
def run_rompt(input_table, output_json):
    cmd = (
        "python ./07.labels_embedding.py -label_input " + input_table + 
        " -output " + output_json
    )
    os.system(cmd)
    

if __name__ == "__main__":
    start_time = time.time()
    # 生成任务列表
    labels_files = os.listdir("./06.summary_labels_duplicate_to_list_1")
    labels_file_path = [
        os.path.join("./06.summary_labels_duplicate_to_list_1", x) for x in labels_files
    ]
    
    output_path = [x.split(".")[0] + ".json"  for x in labels_files]
    output_path = [os.path.join("./07.embedding_result_1",x) for x in output_path]
    os.makedirs("./07.embedding_result_1",exist_ok=True)
    task_list = list(zip(labels_file_path, output_path))
    
    # 多进程执行任务
    cpu_count = multiprocessing.cpu_count() - 1
    with Pool(3) as pool:
        pool.starmap(run_rompt, task_list)
    end_time = time.time()
    total_time = end_time - start_time 
    
    print(f"\n任务数量是 {len(task_list)} :\n", f"\t用时 {total_time}s\n")


